import type { Router } from './../types/user.d'

interface IBreadcrumbs {
  name: string
  path?: string
}

export const mapPathToBreadcrumbs = (path: string, userMenu: Router[]): IBreadcrumbs[] => {
  const breadcrumbs: IBreadcrumbs[] = []
  for (const menu of userMenu) {
    if (menu.path === path) {
      breadcrumbs.push({ name: menu.meta.title })
      return breadcrumbs
    }
    if (menu.children) {
      const breadcrumb = mapPathToBreadcrumbs(path, menu.children)
      if (breadcrumb.length !== 0) {
        breadcrumb.unshift({ name: menu.meta.title })
        return breadcrumb
      }
    }
  }
  return breadcrumbs
}
